package tc.crase.db;

import tc.crase.sys.XdbRoot;

public class AttrId {
	private int id;
	private String url = "";
	
	public AttrId(int id, String url) {
		this.id = id;
		this.url = url;
	}
	
	public int getId() {
		return id;
	}
	
	public String getUrl() {
		return url;
	}
	
	public Xattr searchAttr(Xdb parent) {
		Xdb db = null;
		
		if (url.isEmpty()) {
			db = parent;
		}
		else {
			db = XdbRoot.xdbsys.searchDb(url);
		}
		
		for (Xobject object : db) {
			for (Xattr attr : object) {
				if (attr instanceof XattrLNK) {
					XattrLNK lnk = attr.getAsLNK();
					if (lnk.getId() == id) return attr;
				}
				else if (attr instanceof XattrGRP) {
					XattrGRP grp = attr.getAsGRP();
					if (grp.getId() == id) return attr;
				}
				else if (attr instanceof XattrGIT) {
					XattrGIT git = (XattrGIT)attr;
					if (git.getId() == id) return attr;
				}
			}
		}
		
		return null;
	}
}
